package cn.jingzhuan.fm.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentStatePagerAdapter
import cn.jingzhuan.element.demo.view.fragment.FMAudioIntroFragment
import cn.jingzhuan.element.demo.view.fragment.FMAudioListFragment
import cn.jingzhuan.element.demo.view.util.statusbar.StatusBarCompat
import cn.jingzhuan.fm.R
import cn.jingzhuan.fm.databinding.ActivityFmAlbumDetailBinding
import cn.jingzhuan.fm.pojo.FMAlbum

class FMAlbumDetailActivity : BaseBindingActivity<ActivityFmAlbumDetailBinding>(){

    lateinit var album : FMAlbum

    companion object {
        fun startActivity(context: Context,album:FMAlbum) {
            var intent = Intent(context,FMAlbumDetailActivity::class.java)
            intent.putExtra("album",album)
            context.startActivity(intent)
        }
    }

    override fun onDataBind(savedInstanceState: Bundle?, binding: ActivityFmAlbumDetailBinding?) {
        album = intent.getParcelableExtra("album")
        binding?.album = album
        setUpActionBar(binding?.toolbar)
        StatusBarCompat.translucentStatusBar(this,true)

        val tabs = mutableListOf("介绍", "节目")
        var fragmentList = mutableListOf<Fragment>()
        fragmentList.add(FMAudioIntroFragment())
        fragmentList.add(FMAudioListFragment())


        binding?.viewPager?.adapter = object : FragmentStatePagerAdapter(supportFragmentManager) {

            override fun getItem(position: Int): Fragment = fragmentList[position]

            override fun getCount(): Int = fragmentList.size

            override fun getPageTitle(position: Int): CharSequence? = tabs[position]
        }

        binding?.tabLayout?.setupWithViewPager(binding.viewPager)
        binding?.tabLayout?.getTabAt(1)?.select()
    }

    override fun getLayoutId(): Int  = R.layout.activity_fm_album_detail

}